<template>
  <el-dialog title="新增" :close-on-click-modal="false" :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" label-width="80px">
      <el-form-item label="回访人员id" prop="returnUser">
        <el-input v-model="dataForm.returnUserName" placeholder="回访人员id" disabled></el-input>
      </el-form-item>
      <el-form-item label="回访时间" prop="returnDate">
        <el-date-picker type="date" placeholder="选择日期" v-model="dataForm.returnDate" value-format="yyyy-MM-dd" style="width: 100%;"></el-date-picker>
      </el-form-item>
      <el-form-item label="预约下次回访时间" prop="nextReturnDate" v-if="dataForm.type == 2">
        <el-date-picker type="date" placeholder="选择日期" v-model="dataForm.nextReturnDate" value-format="yyyy-MM-dd" style="width: 100%;"></el-date-picker>
      </el-form-item>
      <el-form-item label="回访类型" prop="returnType">
        <el-select v-model="dataForm.returnType" placeholder="回访类型" size="mini" clearable>
          <el-option label="未回访" :value="3"></el-option>
          <el-option label="已回访" :value="1"></el-option>
          <el-option label="已取消" :value="2"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="回访结果信息" prop="returnInfo">
        <el-input type='textarea' v-model="dataForm.returnInfo" placeholder="回访结果信息"></el-input>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()" :loading="ischeck">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
    import {addObj} from '@/api/eims/salereturnlog'
    import { mapGetters } from 'vuex'

    export default {
    data () {
      return {
        visible: false,
				ischeck: false,
        dataForm: {
          id: 0,
          returnId: '',
          returnUserName: '',
          returnUser: '',
          returnType: '',
          returnInfo: '',
          returnDate: ''
        },
        dataRule: {
          returnId: [
            { required: true, message: '销售商品效期截止回访表id不能为空', trigger: 'blur' }
          ],
          returnUser: [
            { required: true, message: '回访人员id不能为空', trigger: 'blur' }
          ],
          returnInfo: [
            { required: true, message: '回访结果信息不能为空', trigger: 'blur' }
          ],
          returnType: [
            { required: true, message: '回访类型不能为空', trigger: 'blur' }
          ],
          returnDate: [
            { required: true, message: '回访时间不能为空', trigger: 'blur' }
          ],
        }
      }
    },
    computed: {
      ...mapGetters(['userInfo'])
    },
    methods: {
      init (returnId,type) {
        for(let key in this.dataForm){
          this.dataForm[key] = ''
        }
        this.dataForm.returnId = returnId
        this.dataForm.type = type
        this.dataForm.returnUser = this.userInfo.id
        this.dataForm.returnUserName = this.userInfo.realName
        this.visible = true
      },
      // 表单提交
      dataFormSubmit () {
				this.ischeck = true
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            addObj(this.dataForm).then(response => {
              if(response.data.code == '0'){
                this.$message.success('添加成功')
                this.visible = false
                this.$emit('refreshDataList')
              }else{
                this.$message.error(response.data.msg)
              }
              this.ischeck = false
            }).catch(() => {
							this.ischeck = false
						})  
          }else{
						this.ischeck = false
					}
        })
      }
    }
  }
</script>
